--[[
	Lysidia's Open Bags
	
	If you are like me, you tire of the constant bag opening/closing at vendors, the bank, etc, and this addon just automates that.

	It is extremely simple, when active it opens all bags when you talk to a merchant or visit the bank and closes them when you leave.

	No configuration, just install and it runs.
	
	Currently works with:-
		- Guild Bank
		- Player Bank
		- Merchants
		- Trade Window
		- Mailbox
		- Auction House
]]


-- OnEvent Function
function LOB_OnEvent(self, event, ...)
	if ((event == "BANKFRAME_OPENED")	or
		(event == "AUCTION_HOUSE_SHOW")	or
		(event == "MAIL_SHOW")		or
		(event == "TRADE_SHOW")		or
		(event == "MERCHANT_SHOW")	or
		(event == "GUILDBANKFRAME_OPENED")) then
		for i = 0, NUM_CONTAINER_FRAMES, 1 do
			OpenBag(i);
		end
		return;

	else
		for i = 0, NUM_CONTAINER_FRAMES, 1 do
			CloseBag(i);
		end
		CloseAllBags();
		return
	end
end


-- Main Frame Configuration
local LysOpenBags = CreateFrame("Frame");
LysOpenBags:Hide();

-- Register for Event Handling
LysOpenBags:RegisterEvent("BANKFRAME_OPENED");
LysOpenBags:RegisterEvent("BANKFRAME_CLOSED");
LysOpenBags:RegisterEvent("AUCTION_HOUSE_SHOW");
LysOpenBags:RegisterEvent("AUCTION_HOUSE_CLOSED");
LysOpenBags:RegisterEvent("MERCHANT_SHOW");
LysOpenBags:RegisterEvent("MERCHANT_CLOSED");
LysOpenBags:RegisterEvent("MAIL_SHOW");
LysOpenBags:RegisterEvent("MAIL_CLOSED");
LysOpenBags:RegisterEvent("TRADE_CLOSED");
LysOpenBags:RegisterEvent("TRADE_SHOW");
LysOpenBags:RegisterEvent("GUILDBANKFRAME_OPENED");
LysOpenBags:RegisterEvent("GUILDBANKFRAME_CLOSED");


-- Script Handlers
LysOpenBags:SetScript("OnEvent", LOB_OnEvent);

-- Addon Activation Notification
DEFAULT_CHAT_FRAME:AddMessage("Lysidia's Open Bags loaded.", 1, 1, 1);
